package com.leo.default_exchange;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.GetResponse;

public class Consumer {
    public static void main(String[] args) throws Exception {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setUri("amqp://root:123456@192.168.56.204:5672/%2f");

        final Connection connection = factory.newConnection();
        final Channel channel = connection.createChannel();

        /** pull 模式，且使用自动确认ack*/
        final GetResponse getResponse = channel.basicGet("queue.default.ex", true);

        /**不自动确认, 则需手动确认*/
        //channel.basicAck();
        System.out.println("收到的消息：" + new String(getResponse.getBody(), "utf-8"));

        channel.close();
        connection.close();

    }
}